package com.shixun.dds_11.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.shixun.dds_11.entity.DdsAddress;
import com.shixun.dds_11.entity.User;
import com.shixun.dds_11.mapper.DdsAddressMapper;
import com.shixun.dds_11.mapper.UserMapper;
import com.shixun.dds_11.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shixun.dds_11.vo.UserQueryVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author YSP
 * @since 2024-07-05
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {

    @Autowired
    private UserMapper userMapper;

    @Autowired
    DdsAddressMapper ddsAddressMapper;

    /**
     * 根据id获取
     * @param id
     * @return
     */
    public UserQueryVO getByuserId(Integer id) {
        User user = userMapper.selectById(id);
        QueryWrapper<DdsAddress> queryWrapper=new QueryWrapper<DdsAddress>()
                .eq("user_id",id);
        DdsAddress ddsAddress = ddsAddressMapper.selectOne(queryWrapper);
        UserQueryVO userQueryVO=new UserQueryVO();
        userQueryVO.setAddress(ddsAddress.getDetailAddress());
        userQueryVO.setUsername(user.getUsername());
        userQueryVO.setEmail(user.getUsername());
        userQueryVO.setPhone(ddsAddress.getPhone());
        return userQueryVO;
    }
}
